package com.etrans.web.gps.business.system.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.etrans.web.gps.base.service.BaseService;
import com.etrans.web.gps.business.system.domain.AlarmTypeVO;

@Service
public class CommonService extends BaseService {

	public List<HashMap<String, Object>> queryAllPlatform(HashMap<String, Object> param) {
		return this.selectList("commonMapper.queryAllPlatform", param);
	}

	public List<HashMap<String, Object>> queryAllTrade(HashMap<String, Object> param) {
		return this.selectList("commonMapper.queryAllTrade", param);
	}

	public List<HashMap<String, Object>> queryAreaTree(HashMap<String, Object> param) {
		return this.selectList("commonMapper.queryAreaTree", param);
	}

	public List<HashMap<String, Object>> queryVehicleTypeTree(HashMap<String, Object> param) {
		return this.selectList("commonMapper.queryVehicleTypeTree", param);
	}

	public List<HashMap<String, Object>> queryOrganzationTree(HashMap<String, Object> param) {
		return this.selectList("commonMapper.queryOrganzationTree", param);
	}

	public List<HashMap<String, Object>> queryTeminalType(HashMap<String, Object> param) {
		return this.selectList("commonMapper.queryTeminalType", param);
	}

	public List<HashMap<String, Object>> queryEnterprise(HashMap<String, Object> param) {
		return this.selectList("commonMapper.queryEnterprise", param);
	}

	public List<HashMap<String, Object>> queryBusinessScopeTree(HashMap<String, Object> param) {
		return this.selectList("commonMapper.queryBusinessScopeTree", param);
	}
	
	public String queryplatfromName(Map<String,Object> map) {
		return this.selectOne("commonMapper.queryplatfromName", map);
	}
	/**
	 * 查询登录用户权限下的车辆
	 * @param area_id		用户所管辖的区域
	 * @param vehicle_no	针对车牌号模糊查询(不过滤就不需要传)
	 * @return
	 */
	public List<HashMap<String, Object>> queryVeListByRole(HashMap<String, Object> param) {
		return selectList("commonMapper.queryVeListByRole", param);
	}
	
	/**
	 * 查询登陆用户权限下的平台
	 */
	public List<HashMap<String, Object>> queryPlatByRole(Integer area_id,String name) {
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("FullID", String.format("%08d",area_id));
		param.put("selected", "selected");
		param.put("name", name);
		return selectList("commonMapper.queryPlatByRole", param);
	}
	
	/**
	 * 查询登录用户权限下的业户信息 不限制10条
	 * @return 
	 */
	public List<HashMap<String, Object>> queryEnterAndPlatByRoleNotLimit(Integer area_id,String name) {
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("FullID", String.format("%08d",area_id));
		param.put("name", name);
		return selectList("commonMapper.queryEnterAndPlatByRole", param);
	}
	
	/**
	 * 查询登录用户权限下的业户信息 限制10条
	 * @return 
	 */
	public List<HashMap<String, Object>> queryEnterAndPlatByRole(Integer area_id,String name) {
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("FullID", String.format("%08d",area_id));
		param.put("selected", "selected");
		param.put("name", name);
		return selectList("commonMapper.queryEnterAndPlatByRole", param);
	}

	public int queryPlatformCount(HashMap<String, Object> param) {
		return (int) this.selectOne("commonMapper.queryPlatformCount", param);
	}

	/**
	 * 查岗内容下拉
	 * @param param
	 * @return
	 */
	public List<HashMap<String, Object>> queryQuestions(HashMap<String, Object> param) {
		
		return this.selectList("commonMapper.queryQuestions", param);
	}
	
	/**
	 * 根据车牌号查询车辆
	 * @return  
	 */
	public HashMap<String, Object> queryVehicleByVeNo(String vehicle_no) {
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("vehicle_no",vehicle_no);
		return selectOne("commonMapper.queryVehicleByVeNo", param);
	}
	
	/**
	 * 查询所有报警类型
	 * @return  
	 */
	public List<AlarmTypeVO> queryAlarmTypeList() {
		return selectList("commonMapper.queryAlarmTypeList", null);
	}

	/**
	 * 查询所有车辆颜色信息
	 * @return  
	 */
	public List<HashMap<String,Object>> queryVehicleColorList(Integer color_id) {
		HashMap<String,Integer> colorMap = new HashMap<String,Integer>();
		colorMap.put("color_id", color_id);
		return selectList("commonMapper.queryVehicleColorList", colorMap);
	}
	
	/**
	 * 业户查岗下拉
	 * @return  
	 */
	public List<HashMap<String, Object>> selectEnterprise(HashMap<String, Object> param) {
		return this.selectList("commonMapper.selectEnterprise", param);
	}
	
	/**
	 * 根据平台接入码查询平台名称
	 * @param param
	 * @return
	 */
	public String selectplatformName(HashMap<String, Object> param) {
		return this.selectOne("commonMapper.selectplatformName", param);
	}
	
	/**
	 * 查询用户权限下的平台名称
	 * @param param
	 * @return
	 */
	public List<HashMap<String, Object>>  selectqueryplatformbyAreaID(HashMap<String, Object> param) {
		return this.selectList("commonMapper.queryplatformbyAreaID", param);
	}
	
	/**
	 * 根据区域id查询区域名称
	 * @return  
	 */
	public List<Integer> queryAreaListById(Integer area_id) {
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("FullID", String.format("%08d",area_id));
		return this.selectList("commonMapper.queryAreaIdById", param);
	}
	
	/**
	 * 根据区域id查询区域名称
	 * @return  queryenterpriseNameById
	 */
	public List<String> queryenterpriseNameById(Integer id) {
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("enterpriseid",id);
		return this.selectList("commonMapper.queryenterpriseNameById", param);
	}
	
	/**
	 * 根据区域id 查询区域名称
	 * @param id
	 * @return
	 */
	public Map<String,String> findAreaNameById(String areaId){
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("areaId",areaId);
		return this.selectOne("commonMapper.findAreaNameById", param);
	}
	
	/**
	 * 根据区域id 查询行政级别
	 * @param id
	 * @return
	 */
	public Integer findAreaLevelById(Integer areaId){
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("areaId",areaId);
		return this.selectOne("commonMapper.findAreaNameByLevel", param);
	}
	
	/**
	 * 根据区域id和level 查询区域名称
	 * @param id
	 * @return
	 */
	public List<HashMap<String, Object>> findAreaName(HashMap<String, Object> param){
		return this.selectList("commonMapper.queryAreaName", param);
	}

	/**
	 * 根据区域id查询区域id对应的所有业户
	 * @param list
	 * @return
	 */
	public List<HashMap<String, Object>> queryEnterpriseByIds(List<Integer> list) {
		return this.selectList("commonMapper.queryEnterpriseByIds", list);
	}

	/**
	 * 根据业户id 查询业户所有车辆
	 * @param id
	 * @return
	 */
	public List<HashMap<String,Object>> queryCarByEnterpriseId(Integer enterprise_id){
		HashMap<String, Object> param = new HashMap<String, Object>();
		if (enterprise_id != null) {
			param.put("enterprise_id",enterprise_id);
		}
		return this.selectList("commonMapper.queryCarByEnterpriseId", param);
	}
	
	/**
	 * 查询权限下所有司机
	 * @return
	 */
	public List<HashMap<String, Object>> queryDriverListByRole(HashMap<String, Object> param) {
		return this.selectList("commonMapper.queryDriverListByRole", param);
	}

	/**
	 * 去掉父节点区域id
	 * @return
	 */
	public List<HashMap<String, Object>> findAreaIdByLevelAndIds(HashMap<String, Object> param) {
		return this.selectList("commonMapper.findAreaIdByLevelAndIds", param);
	}
}
